package com.wclass.mapper;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wclass.entity.BaseAppUser;
import com.wclass.entity.BaseFocus;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 关注表 Mapper 接口
 * </p>
 *
 * @author 张浩高
 * @since 2018-12-21
 */
public interface BaseFocusMapper extends BaseMapper<BaseFocus> {


    /**
     * id
     * 统计关注数量
     *
     * @param userId
     * @return
     */
    @Update("update base_app_user set focus_num=(select count(*) from base_focus where user_id=${userId} and state=0) " +
            "where id =${userId} and state=0")
    int StatFocusNum(@Param("userId") Long userId);


    /**
     * 统计数量粉丝
     *
     * @param userId
     * @return
     */
    @Update("update base_app_user set fan_num=(select count(*) from base_focus where focus_user_id=${userId} and state=0)" +
            " where id =${userId} and state=0")
    int StatFanNum(@Param("userId") Long userId);

    @Select("select * from base_focus info " +
            "left join base_app_user appUser on info.user_id = appUser.id " +
            "where info.state=0 and appUser.state=0 " +
            "${ew.sqlSegment}")
    List<BaseAppUser> selectFansList(@Param("ew") EntityWrapper<BaseFocus> ew);
}
